home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / MPW Extras ƒ / MPW / Scripts / InsertFile < prev    next >
Encoding:
Text File  |  1991-07-29  |  1.2 KB  |  38 lines  |  [TEXT/MPS ]

  1. # InsertFile - script to insert text from a chosen file into the current window
  2.  
  3. Set FName `Begin; NewGetFile -b "Insert" -t TEXT -r; Set GetStatus {Status}; End`
  4. If ({GetStatus} == 0)
  5.     # no errors or cancellation
  6.     If ("{FName}" == "{Active}")
  7.         # files to be inserted from and to are the same!
  8.         Alert "{0}:∂nSorry, you cannot insert text from a file into itself."
  9.     Else
  10.         # test if the source file is already open
  11.         Set NoClose 0
  12.         For i in `Windows`
  13.             If "{i}" == "{FName}"
  14.                 Set NoClose 1
  15.                 Break
  16.             End  # If {i}
  17.         End  # For i
  18.         Set OldActive "{Active}"
  19.         If ({NoClose} == 0)
  20.             Open -r "{FName}"                    # display the source window (as read-only)
  21.         Else
  22.             Open "{FName}"                        # make the source window frontmost 
  23.         End  # If {NoClose }
  24.         If ({Status} == 0)
  25.             # no errors
  26.             Target "{OldActive}"                # make the old active window the target (window updates that slow the process don't occur in target window
  27.             TypeFile "{FName}" > "{Target}".§    # transfer the text
  28.             Open "{OldActive}"                    # restore the old active window
  29.             If ({NoClose} == 0)
  30.                 Close -n "{FName}"                # close the source window
  31.             End  # If {NoClose}
  32.         Else
  33.             Alert "{0}:∂nUnable to open the file {FName}"
  34.         End  # If {Status}
  35.     End  # If {FName}
  36. End  # If {SaveStatus}
  37.  
  38. # end of InsertFile